import logging
import webapp2

from twilio import TwilioException
import twimlgae


class Index(webapp2.RequestHandler):   
    def get(self):
        r = twimlgae.Response()
        try:
            gather = r.gather(action="/ura",numDigits=1,timeout=5,method="GET")
            k=self.request.get('Digits')
            if k=='1':
                gather.say(text='You pressed key one')
            elif k=='2':
                gather.say(text='Voce pressionou tecla dois',language='pt')
            elif k=='3':
                gather.say(text='U hebt op toets drie',language='nl')
            else:
                gather.say(text='Welcome! Press key two to continue in english.')
                gather.say(text='Bem Vindo! Tecle um para continuar em portugues.',language='pt')
                gather.say(text='Druk op de knop om verder te gaan op de drie Nederlanders',language='nl')                                     
        except TwilioException, e:
            logging.info(e.msg)
            r.say("Sorry! something wrong here")
        self.response.headers['Content-Type'] = "text/xml"
        self.response.write(r)
        return 
        
app = webapp2.WSGIApplication([
  (r'.*/mp3/.*$',twimlgae.MP3Handler),
  (r'.*',Index)
],debug=True)